from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import ddddocr
from selenium.webdriver.common.by import By
import requests

service = Service(executable_path=r"E:\mypython2411\chromedriver.exe")
driver = webdriver.Chrome(service=service)
# driver.maximize_window()
# 打开url
driver.get("https://www.gushiwen.cn/user/login.aspx?from=http://www.gushiwen.cn/user/collect.aspx")
# 拿到验证码图片的src
src = driver.find_element(By.XPATH, '//*[@id="imgCode"]').get_attribute('src')
print(src)
response  =  requests.get(src)
# 下载图片
with open('./imgs/古诗文.png','wb') as f:
    f.write(response.content)
# 识别
ocr = ddddocr.DdddOcr()
with open("imgs/古诗文.png", 'rb') as f:
    bytes = f.read()
    result = ocr.classification(bytes)
    print(result)

driver.quit()


